// 2023-11-12 13:14:15这样的
let reg = /[0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}/g

// 将当前时间,转为2023-11-12 13:14:15这样的
function getNow () {
  let date = new Date()
  return date.getFullYear().toString() + '-' +
    pad2(date.getMonth() + 1) + '-' +
    pad2(date.getDate()) + ' ' +
    pad2(date.getHours()) + ':' +
    pad2(date.getMinutes()) + ':' +
    pad2(date.getSeconds())
}

function pad2 (n) {
  return n < 10 ? '0' + n : n
}

export const replaceTime = old => {
  const now = getNow()
  return old.replace(reg, now)
}
